#ifndef __MESSAGEQUEUE_HH_
#define __MESSAGEQUEUE_HH_

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <math.h>
#include <error.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

#include "mylog.h"

/**********************************************
 *          Eroor code
 *********************************************/
#define MSGQUEUE_SUCCESS (0)
#define MSGQUEUE_INVALID (-1)
#define MSGQUEUE_SENDERR (-2)
#define MSGQUEUE_RECVERR (-3)
/**********************************************
 *        Eroor code end
 *********************************************/

#define MSG_DEBUG

/*
 * 这个结构体为消息队列需要发送的消息内容
 * */
typedef struct{
    char data[BUFSIZ];
}MSG_DATA;

typedef  struct {
    long int message_type;
    MSG_DATA msgData;
}MESSAGE_QUEUE_HANDLE;

class MessageQueue
{
public:
    MessageQueue( int id );
    ~MessageQueue();

    static MessageQueue* createNew(int id );
    int SendMesage( long int msgType, MSG_DATA data, int msgflg = 0 );
    int RecvMesage( long int msgType, MSG_DATA &data, int msgflg = 0 );

protected:

private:
    bool createMsg = false;      //if MessageQueue(int shareId, long long memSize ) true
    const char *fname = "/home";    // ftok fname
    key_t keyId = -1;           // shmKey = ftok( fname, MessageQueueId );
    int msgId = -1;              // shmId = shmget( fname, MessageQueueId );
};

#endif
